﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Foundation.Metadata;
using Windows.Web.Http;

namespace App1
{
    public class DataModel
    {
        public static async Task<BookSearch> SearchBooks(string keyword, int page)
        {
            HttpClient request = new HttpClient();
            Uri address = new Uri("http://it-ebooks-api.info/v1/search/" + keyword + "/page/" + page.ToString());
            var result = await request.GetAsync(address);

            BookSearch data = JsonConvert.DeserializeObject<BookSearch>(result.Content.ToString());

            return data;
        }


        public static async Task<BookSearchList> GetBookList(string name = "books", int init = 0, int count = 3)
        {
            BookSearchList list = new BookSearchList();
            for (int i = 0; i < count; i++)
            {
                var data = await DataModel.SearchBooks(name, i + init);
                list.booksearchlist.Add(data);
            }
            return list;
        }

    }
}
